package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ComplainMapper;
import com.ruoyi.system.domain.Complain;
import com.ruoyi.system.service.IComplainService;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-03
 */
@Service
public class ComplainServiceImpl implements IComplainService 
{
    @Resource
    private ComplainMapper complainMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param complainId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public Complain selectComplainByComplainId(Long complainId)
    {
        return complainMapper.selectComplainByComplainId(complainId);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param complain 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<Complain> selectComplainList(Complain complain)
    {
        return complainMapper.selectComplainList(complain);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param complain 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertComplain(Complain complain)
    {
        complain.setFakeDelete(1L);
        complain.setUserId(101L);
        complain.setComplainTime(DateUtils.getNowDate());
        return complainMapper.insertComplain(complain);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param complain 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateComplain(Complain complain)
    {
        complain.setUserId(SecurityUtils.getLoginUser().getUserId());
        return complainMapper.updateComplain(complain);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param complainIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteComplainByComplainIds(Long[] complainIds)
    {
        String[] str = new String[complainIds.length];
        for(int i = 0; i < complainIds.length; i++){
            Complain complain=complainMapper.selectComplainByComplainId(complainIds[i]);
            if (complain.getUserId()==101) {
               str[i] = "0";
            }else {
                str[i] = "1";
            }
        }
        String toString = Arrays.toString(str);
        if (toString.contains("0")){
            return 101;
        }else {
            return complainMapper.deleteComplainByComplainIds(complainIds);
        }

    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param complainId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteComplainByComplainId(Long complainId)
    {
        return complainMapper.deleteComplainByComplainId(complainId);
    }

    @Override
    public List<Complain> complainList() {
        Complain complain=new Complain();
        complain.setUserId(SecurityUtils.getLoginUser().getUserId());
        return complainMapper.complainList(complain);
    }

    @Override
    public List<Complain> noReplyComplain() {
        return complainMapper.noReplyComplain();
    }

    @Override
    public List<Complain> getAnonymous() {
        return complainMapper.getAnonymous();
    }

    @Override
    public List<Complain> getNoAnonymous() {
        return complainMapper.getNoAnonymous();
    }

}
